package Receive;

import java.io.IOException;
import java.io.Serializable;

import android.util.Log;

public class Search_Report extends Receive_Packet implements Serializable {

	//public int store_code;
	public float avg_grade;
	public Opinion[] op;
	public int op_count;
	//public String store_name;
	//public String store_phone;
	//public double latitude;
	//public double longitude;
	public Store store;

	public Search_Report(byte[] packet) {
		super(packet);
		store = new Store();
	}

	public void get_code(byte[] packet) {
		byte[] temp = new byte[4];
		System.arraycopy(packet, 5, temp, 0, 4);
		this.store.code = byteToint(temp);
		//this.store_code = byteToint(temp);
	}

	public void get_grade(byte[] packet) {
		byte[] temp = new byte[4];
		System.arraycopy(packet, 9, temp, 0, 4);
		this.avg_grade = byteTofloat(temp);
	}
	
	public void get_Opinion(byte[] packet) throws IOException {
		int temp_length = packet.length - 13;
		byte[] temp = new byte[temp_length];
		System.arraycopy(packet, 13, temp, 0, temp_length);
		String temp_string = new String(temp, "euc-kr");
		String[] opinions = temp_string.split("\r\n");
		
		this.store.name = opinions[0];
		this.store.phone = opinions[1];
		this.store.time = opinions[2];
		this.store.rest_day = opinions[3];
		this.store.latitude = Double.parseDouble(opinions[4]);
		this.store.longitude = Double.parseDouble(opinions[5]);
		

		op = new Opinion[(opinions.length - 6) / 5];
		for (int i = 0; i < (opinions.length - 6) / 5; i++) {
			op[i] = new Opinion();
		}

		for (int i = 0; i < (opinions.length - 6) / 5; i++) {
			op[i].num = opinions[5 * i + 6];
			op[i].nick = opinions[5 * i + 7];
			op[i].opinion = opinions[5 * i + 8];
			op[i].like = opinions[5 * i + 9];
			op[i].unlike = opinions[5 * i + 10];
		}

	}
	
	public float return_grade() {
		return avg_grade;
	}

}
